import type { ConfigType, paramsType } from '../types'
export const formBtn = (formApi: ConfigType, params: any, cb: Function) => {
  const onSearch = () => {
    if (formApi.fApi?.validate) {
      formApi.fApi.validate(async (valid: any) => {
        if (valid) {
          params.value.pageNo = 1
          cb()
        }
      })
    } else {
      params.value.pageNo = 1
      cb()
    }
  }
  const onClear = () => {
    formApi.fApi.rule.map((v: any) => v.field).map((v: any) => {
      if (v) formApi.fApi.setValue(v, null)
    })
    params.value.pageNo = 1
    cb()
  }
  return {
    onSearch,
    onClear
  }
}